@extends('admin.main')
@section('head')
    @if(isset($hideHeader))
        <style>
            body {
                padding: 0;
            }
        </style>
    @endif
@endsection
@section('body')
    <!-- 标题栏 -->
    <div class="cf">
    <!-- 高级搜索 -->
        <div class="search-form fr cf">
            <div style="float: left;margin-right: 10px;line-height: 26px;">
                @if(plat_identify() == 'admin')
                    <select name="shop_id" id="shop_id"style="height: 30px;">
                        <option value="0">请选择店铺</option>
                        @if(count($shops))
                            @foreach($shops as $value)
                                <option value="{{$value['id']}}" @if($value['id'] == request('shop_id')) selected @endif>{{$value['shop_name']}}</option>
                            @endforeach
                        @endif
                    </select>
                @endif

                <select name="type" id="type" style="height: 30px;">
                    <option value="0" @if($type == 0) selected @endif>请选择搜索类型</option>
                    <option value="1" @if($type == 1) selected @endif>ID</option>
                    <option value="2" @if($type == 2) selected @endif>姓名</option>
                    <option value="3" @if($type == 3) selected @endif>手机号</option>
                    <option value="4" @if($type == 4) selected @endif>公司名称</option>
                    <option value="5" @if($type == 5) selected @endif>地址</option>
                </select>
            </div>
            <div class="sleft">
                <input type="text" name="keyword" class="search-input" value="{{$keyword}}"
                       placeholder="请输入对应的搜索内容">
                <a class="sch-btn" href="javascript:;" id="search" url="{{urlPlat($ctr,'getReferMemberSet')}}"><i
                            class="btn-search"></i></a>
            </div>
        </div>
    </div>
    <!-- 数据列表 -->
    <div class="data-table table-striped">
        <table class="">
            <thead>
            <tr>
                <th class="">ID</th>
                <th class="">类型</th>
                <th class="">头像</th>
                <th class="">昵称</th>
                <th class="">姓名</th>
                <th class="">手机号</th>
                <th class="">单位名称</th>
                <th class="">地址</th>
                <th class="">操作</th>
            </tr>
            </thead>
            <tbody>
            @if(count($rows['data']))
                @foreach($rows['data'] as $v)
                    <tr>
                        <td>{{$v['id']}}</td>
                        <td>{{$v['address'] ? $v['address']['type'] == 1 ? '单位': ($v['address']['type'] == 2 ? '家庭' : '') : ''}}</td>
                        <td><img src="{{$v['avatarurl']}}" width="20px"/></td>
                        <td>{{$v['nickname']}}</td>
                        <td>{{$v['address'] ? $v['address']['name'] : ''}}</td>
                        <td>{{$v['address'] ? $v['address']['mobile'] : ''}}</td>
                        <td>{{$v['address'] ? $v['address']['company_name'] : ''}}</td>
                        <td>{{$v['address'] ? $v['address']['address'] : ''}}</td>
                        <td>
                            <a title="设为渠道" href="javascript:;" onclick="channelSet({{$v['id']}})">设为渠道</a>
                        </td>
                    </tr>
                @endforeach
            @else
                <td colspan="15" class="text-center"> aOh! 暂时还没有内容!</td>
            @endif
            </tbody>
        </table>
    </div>
    <div class="page">
        @if($rows['last_page']>1)
            <div>
                <a class="first" href="{{urlPlat($ctr,'getReferMemberSet',['page'=>1,'keyword'=>$keyword,'type'=>$type])}}">首页</a>
                @if($rows['prev_page_url'])
                    <a class="prev" href="{{$rows['prev_page_url']}}">&lt;&lt;</a>
                @endif
                @if(count($rows['pageNoList']))
                    @foreach($rows['pageNoList'] as $v)
                        @if($rows['current_page'] == $v)
                            <span class="current">{{$v}}</span>
                        @else
                            <a class="num" href="{{urlPlat($ctr,'getReferMemberSet',['page'=>$v,'keyword'=>$keyword,'type'=>$type,'shop_id'=>request('shop_id')])}}">{{$v}}</a>
                        @endif
                    @endforeach
                @endif
                @if($rows['next_page_url'])
                    <a class="next" href="{{$rows['next_page_url']}}">&gt;&gt;</a>
                @endif
                <a class="last" href="{{urlPlat($ctr,'getReferMemberSet',['page'=>$rows['last_page'],'keyword'=>$keyword,'type'=>$type,'shop_id'=>request('shop_id')])}}">末页</a>
                <span class="rows">共 {{$rows['total']}} 条记录</span>
            </div>
        @endif
    </div>
@endsection

@section('script')
    <script src="/static/layer/extend/layer.ext.js"></script>
    <script type="text/javascript">
        //搜索功能
        $("#search").click(function () {
            var url = $(this).attr('url');
            var shop_id = $("#shop_id").val() || 0;
            var query = $('.search-form').find('input').serialize();
            var type = $('#type').val();
            query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
            query = query.replace(/^&/g, '');
            if (url.indexOf('?') > 0) {
                url += '&' + query + '&type=' + type + '&shop_id=' + shop_id;
            } else {
                url += '?' + query + '&type=' + type + '&shop_id=' + shop_id;
            }
            window.location.href = url;
        });

        //回车自动提交
        $('.search-form').find('input').keyup(function(event){
            if(event.keyCode===13){
                $("#search").click();
            }
        });

        function channelSet(id) {
            var shop_id = GetUrlString('shop_id');
            if(shop_id == 0 || shop_id == null || shop_id == undefined || shop_id == '') {
                layer.alert('请选择店铺');
            } else {
                layer.prompt({
                    formType:0,
                    title:'佣金设置（元/桶）',
                },function(val, index){
                    var reg = /^[0-9]+.?[0-9]*$/;
                    if(reg.test(val)) {
                        $.ajax({
                            url:"{{urlPlat($ctr,'postReferMemberSet')}}",
                            data:{refer_ratio:val, shop_id:shop_id, mid:id},
                            type:'post',
                            success:function(res){
                                if(res.status == 1){
                                    layer.msg('设置成功');
                                    parent.window.location.reload()
                                } else {
                                    layer.msg(res.msg)
                                }
                            },
                            fail:function(){
                                layer.msg('设置失败')
                            }
                        })
                    } else {
                        layer.msg('请输入数字')
                    }
                    layer.close(index);
                });
            }
        }

        function GetUrlString(name) {
            var url = window.location.href;
            if (url.indexOf('?') != -1) {
                url = url.split('?')[1];
            }
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = url.match(reg);
            if (r != null) return unescape(r[2]);
            return null;
        }
    </script>
@endsection
